package com.jin;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import javax.swing.*;
import javax.swing.border.EmptyBorder;

import com.jin.domain.CheckItem;

/**
 * 2 判断 1填空 系统常量
 *
 * @Author <a href="mailto:lijing1@wxchina.com@wxchina.com">Lijin</a>
 * @Description:
 * @Create: 2021年6月22日
 */
public class Panduanti extends JFrame {

    private JPanel contentPane;

    /**
     * Launch the application.
     */

    /**
     * Create the frame.
     */
    public Panduanti(int indexOfItem) {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 600, 373);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);
        contentPane.setLayout(null);
        int threeIndex = ExamResult.getIndexAndIncrement();
        JLabel label = new JLabel("第" + threeIndex + "题");
        label.setBounds(10, 22, 300, 15);
        contentPane.add(label);
        List<CheckItem> list = ItemSource.checkItems;
        CheckItem checkItemThree = list.get(indexOfItem);
        JTextArea textArea = new JTextArea();
        textArea.setText(checkItemThree.getItemTitle());
        textArea.setBounds(10, 58, 550, 24);
        contentPane.add(textArea);

        JRadioButton radioButton = new JRadioButton("对");
        radioButton.setBounds(10, 94, 121, 23);
        contentPane.add(radioButton);

        JRadioButton radioButton_1 = new JRadioButton("错");

        ButtonGroup btnGroupThree = new ButtonGroup();
        btnGroupThree.add(radioButton);
        btnGroupThree.add(radioButton_1);

        radioButton_1.setBounds(202, 94, 121, 23);
        contentPane.add(radioButton_1);
        int indexNew = indexOfItem + 1;
        if (indexNew >= list.size()) {
            indexNew = 0;
        }
        int fourIndex = ExamResult.getIndexAndIncrement();
        JLabel label_1 = new JLabel("第" + fourIndex + "题");
        label_1.setBounds(10, 140, 300, 15);
        contentPane.add(label_1);
        CheckItem checkItemFour = list.get(indexNew);
        JTextArea textArea_1 = new JTextArea();
        textArea_1.setText(checkItemFour.getItemTitle());
        textArea_1.setBounds(10, 179, 550, 24);
        contentPane.add(textArea_1);

        JRadioButton radioButton_2 = new JRadioButton("对");
        radioButton_2.setBounds(10, 232, 121, 23);
        contentPane.add(radioButton_2);

        JRadioButton radioButton_3 = new JRadioButton("错");

        ButtonGroup btnGroupFour = new ButtonGroup();
        btnGroupFour.add(radioButton_2);
        btnGroupFour.add(radioButton_3);

        radioButton_3.setBounds(202, 232, 121, 23);
        contentPane.add(radioButton_3);

        JButton button = new JButton("下一题");
        button.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                Boolean three = null;
                boolean threeR = radioButton.isSelected();
                boolean threeF = radioButton_1.isSelected();
                if (threeR) {
                    three = true;
                }
                if (threeF) {
                    three = false;
                }

                Boolean four = null;
                boolean fourR = radioButton_2.isSelected();
                boolean fourF = radioButton_3.isSelected();
                if (fourR) {
                    four = true;
                }
                if (fourF) {
                    four = false;
                }
                if (three == null || four == null) {
                    JOptionPane.showMessageDialog(contentPane, "必须作答",
                            "标题", JOptionPane.WARNING_MESSAGE);
                    return;
                }
                if (checkItemThree.isAnswer() == three) {
                    ExamResult.add("第" + threeIndex + "题:正确");
                } else {
                    ExamResult.add("第" + threeIndex + "题:错误");
                    ExamResult.add("正确答案:" + ((checkItemThree.isAnswer())?"对":"错"));
                }

                if (checkItemFour.isAnswer() == four) {
                    ExamResult.add("第" + fourIndex + "题:正确");
                } else {
                    ExamResult.add("第" + fourIndex + "题:错误");
                    ExamResult.add("正确答案:" + ((checkItemFour.isAnswer())?"对":"错"));
                }
                System.out.println(ExamResult.info());
                Tiankongti tiankongti=new Tiankongti();
                tiankongti.setVisible(true);
            }
        });
        button.setBounds(202, 284, 93, 23);
        contentPane.add(button);
    }
}
